from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import numpy as np

data = np.loadtxt('../data/wine.data', delimiter=',')
X = data[:, 1:]
y = data[:, 0:1]
X_train, X_test, y_train, y_test = train_test_split(X, y.ravel(), train_size=0.8, random_state=0)
# 补充定义弱分类器的代码
rf = DecisionTreeClassifier()
# 补充定义、训练AdaBoost分类器的代码
model = AdaBoostClassifier(base_estimator=rf, learning_rate=0.5, algorithm='SAMME')
model.fit(X_train, y_train)

# 补充评估模型在测试集上的精度代码
y_test_hat = model.predict(X_test)
print("test accuarcy:", accuracy_score(y_test, y_test_hat))
